import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'app/routes/app_pages.dart';
import 'app/theme/app_theme.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  
  // 根据平台设置不同的初始化配置
  if (kIsWeb) {
    // Web平台特定的初始化
    runApp(const MyApp());
  } else {
    // 移动端平台设置屏幕方向
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.landscapeRight,
    ]).then((_) {
      runApp(const MyApp());
    });
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: '医院信息系统',
      debugShowCheckedModeBanner: false,
      theme: AppTheme.light,
      darkTheme: AppTheme.dark,
      themeMode: ThemeMode.light,
      initialRoute: AppPages.INITIAL,
      getPages: AppPages.routes,
      defaultTransition: Transition.fade,
      // 添加错误处理
      onInit: () {
        Get.config(
          enableLog: true,
          logWriterCallback: (String text, {bool isError = false}) {
            if (isError) {
              debugPrint('Error: $text');
            } else {
              debugPrint('Log: $text');
            }
          },
        );
      },
    );
  }
}